const { remmend } = require('./src/mock')
const bodyParser = require('body-parser')
const userList = [{
  user: '张三',
  pwd: '123'
}, {
  user: '李四',
  pwd: '456'
}]
module.exports = {
  devServer: {
    before(app) {
      app.use(bodyParser.json())
      // 列表
      app.get('/api/remmend', (req, res) => {
        res.json({
          code: 200,
          data: remmend
        })
      })
      // 详情
      app.post('/api/detail', (req, res) => {
        const { id } = req.body;
        const o = remmend.find(item => item.id === id)
        res.send({
          code: 200,
          data: o
        })
      })
      // 登录接口
      app.post('/api/user/login', (req, res) => {
        const { user, pwd } = req.body;
        const o = userList.find(item => item.user === user && item.pwd === pwd)
        if (o) {
          res.send({
            code: 200,
            mess: '登录成功',
            token: user
          })
        } else {
          res.send({
            code: 404,
            mess: '账户密码错误，重新登录'
          })
        }
      })
    }
  }
}